package com.hzy.mapper;

import com.hzy.pojo.Article;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ArticleMapper {
    //新增
    @Insert("insert into article(title, content, cover_img, state, category_id, create_user, create_time, update_time)"+
            "values(#{title},#{content},#{coverImg},#{state},#{categoryId},#{createUser},#{createTime},#{updateTime})")
    void add(Article article);

    //分页查询
    List<Article> list(Integer userId, Integer categoryId, String state);

    //更新文章
    @Update("UPDATE article SET  title = #{article.title}, content = #{article.content}, cover_img = #{article.coverImg}, state = #{article.state}, category_id = #{article.categoryId}, update_time = now() WHERE create_user = #{id} and id= #{article.id}")
    void put(@Param("id") Integer id, @Param("article") Article article);

    //获取文章详情
    @Select("SELECT * FROM article WHERE id=#{id}")
    Article getDetail(Integer id);

    //删除文章
    @Delete("DELETE FROM article WHERE id = #{id}")
    void delete(Integer id);

}
